//
//  ResponseTests.m
//  post
//
//  Created by Hyo Jung Lee on 11. 12. 30..
//  Copyright (c) 2011 __MyCompanyName__. All rights reserved.
//

#import "ResponseTests.h"
#import "JSONKit.h"
#import "Response.h"
#import "RemoveResponse.h"
#import "SendTalkResponse.h"
#import "TalkListResponse.h"

@implementation ResponseTests

// All code under test must be linked into the Unit Test bundle
- (void)testResponse
{
    NSString * message = @"가입성공";
    
    NSMutableDictionary *testDic = [NSMutableDictionary dictionaryWithCapacity:2];
    [testDic setValue:@"0" forKey:KEY_RESULT];
    [testDic setValue:message forKey:KEY_MESSAGE];
    
    Response * response = [[[Response alloc] initWidhDictionary:testDic] autorelease];
    
    STAssertTrue([response result] == 0, @"[response result] is Fail");
    STAssertEquals([response message], message, @"[response message] is Fail");
}

- (void)testRemoveResponse
{
    NSString * message = @"삭제성공";
    
    NSMutableDictionary *testDic = [NSMutableDictionary dictionaryWithCapacity:3];
    [testDic setValue:@"0" forKey:KEY_RESULT];
    [testDic setValue:message forKey:KEY_MESSAGE];
    [testDic setValue:@"100" forKey:KEY_RID];
    
    RemoveResponse * response = [[[RemoveResponse alloc] initWidhDictionary:testDic] autorelease];
    
    STAssertTrue([response result] == 0, @"[response result] is Fail");
    STAssertEquals([response message], message, @"[response message] is Fail");
    STAssertEquals([response rid], @"100", @"[response rid] is Fail");
}

- (void)testSendTalkResponse
{
    NSString * message = @"전송성공";
    
    NSMutableDictionary *testDic = [NSMutableDictionary dictionaryWithCapacity:4];
    [testDic setValue:@"0" forKey:KEY_RESULT];
    [testDic setValue:message forKey:KEY_MESSAGE];
    [testDic setValue:@"100" forKey:KEY_RID];
    [testDic setValue:@"1" forKey:KEY_TALK_SEQ];
    
    SendTalkResponse * response = [[[SendTalkResponse alloc] initWidhDictionary:testDic] autorelease];
    
    STAssertTrue([response result] == 0, @"[response result] is Fail");
    STAssertEquals([response message], message, @"[response message] is Fail");
    STAssertEquals([response rid], @"100", @"[response rid] is Fail");    
    STAssertEquals([response talkSeq], @"1", @"[response talkSeq] is Fail");    
}

- (void)testTalkListResponse
{
    NSString * message = @"리스트성공";
    
    NSMutableDictionary *testDic = [NSMutableDictionary dictionaryWithCapacity:10];

    [testDic setValue:@"0" forKey:KEY_RESULT];
    [testDic setValue:message forKey:KEY_MESSAGE];
    
    //  TalkInfo
    {
        NSMutableArray * array = [NSMutableArray arrayWithCapacity:10];
        
        {
            NSMutableDictionary * dic = [NSMutableDictionary dictionaryWithCapacity:10];
            [dic setValue:@"ma001" forKey:KEY_ID];
            [dic setValue:@"남" forKey:KEY_NAME];
            [dic setValue:@"001" forKey:KEY_RID];
            {
                NSMutableArray * _array = [NSMutableArray arrayWithCapacity:10];
                {
                    NSMutableDictionary * _dic = [NSMutableDictionary dictionaryWithCapacity:2];
                    [_dic setValue:@"1" forKey:KEY_TALK_SEQ];
                    [_dic setValue:@"안녕" forKey:KEY_TALK];
                    
                    [_array addObject:_dic];
                }
                
                {
                    NSMutableDictionary * _dic = [NSMutableDictionary dictionaryWithCapacity:2];
                    [_dic setValue:@"3" forKey:KEY_TALK_SEQ];
                    [_dic setValue:@"변태" forKey:KEY_TALK];
                    
                    [_array addObject:_dic];
                }
                
                [dic setValue:_array forKey:KEY_TALK_ITEM];
            }
            
            [array addObject:dic];
        }
        
        [testDic setValue:array forKey:KEY_TALK_INFO];
    }

    TalkListResponse * response = [[TalkListResponse alloc] initWidhDictionary:testDic];
    NSArray * talkInfoArray = [response talkInfo];
    NSLog(@"talkInfo[%@]", talkInfoArray);
    
//    {	
//		"RESULT":0,
//		"MESSAGE":"리스트성공",
//		"TALK_INFO":[
//                     {
//                         "ID":"ma001",
//                         "NAME":"남",
//                         "RID":"001",
//                         "TALK_ITEM":[
//                         {"TALK_SEQ":"1","TALK":"안녕"},
//                         {"TALK_SEQ":"3","TALK":"변태"}
//                                 ]
//                     }, 
//                     {
//                         "ID":"fa001",
//                         "NAME":"여", 
//                         "RID":"001",
//                         "TALK_ITEM":[
//                         {"TALK_SEQ":"1","TALK":"하이"},
//                         {"TALK_SEQ":"3","TALK":"ㅋㅋㅋ"}
//                                 ]
//                     } 
//                   ]
//    }
}



@end
